package com.etc.iodemo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author: knowno
 * @create: 2024-09-11 16:54
 * @Version 1.0
 **/
public class TestFileWriter {
    public static void main(String[] args) throws IOException {

        //FIleWriter

//        public FileWriter(String fileName, boolean append) throws IOException {
//            super(new FileOutputStream(fileName, append));
//        }

        String filepath = "d:\\demo\\demo.txt";
        File file = new File(filepath);
        if (!file.exists()){
            File parentFile = file.getParentFile();
            System.out.println(parentFile.getAbsolutePath());
            boolean newFile = parentFile.mkdir();

        }
        //1 创建对象 append表示是否追加.
        FileWriter fileWriter = new FileWriter(filepath,true);

        //2 写入
        fileWriter.write("public class Hello{public}\r\n");
        System.out.println("写入成功!");

        //3 关闭
        fileWriter.close();

    }
}
